package metier.sess;

import java.util.List;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import metier.entities.Transport;
import metier.entities.Ville;


@Stateless(name="Ville")
public class VilleEJBImpl implements IVilleLocal,IVilleRemote{
	@PersistenceContext(unitName="PU_Cargaison")
	private EntityManager em;

	@Override
	public void addVille(Ville t) {
		em.merge(t);
		
	}

	@Override
	public List<Ville> getAllVille() {
		Query req=em.createQuery("select v from Ville v");
		return req.getResultList();
	}
	
	@Override
	public List<Ville> getAllActiveVille() {
		Query req=em.createQuery("select v from Ville v where v.statut=true");
		return req.getResultList();
	}
	

	@Override
	public Ville getVille(Integer Id) {
		Ville v=em.find(Ville.class, Id);
		return v;
	}

	@Override
	public void updateVille(Ville t) {
		em.merge(t);
		
	}

	@Override
	public void deleteVille(Integer Id) {
		Ville v=getVille(Id);
		em.remove(v);
		
	}

}
